package com.samsungmobile.common_module.Bean;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Date;

import org.apache.commons.lang.StringEscapeUtils;

import com.samsungmobile.common.Logger;

public class AlbumItem extends Item {

	/**
	 * Unique id for track
	 */
	String upc;		
	
	/**
	 * Name of the artist
	 */
	String author;	
	
	/**
	 * Name of album
	 */
	String title;
	
	/**
	 * Date album was released	
	 */
	Date releaseDate;	
	
	/**
	 * Album Cover image URL
	 */
	String coverImagePath;
	
	/**
	 * Genre ID
	 */
	long genreId;
	
	/**
	 * Name of genre 
	 */
	String genreName;
	
	protected String shortAuthor = "";
	
	String detailURL = "/entertainment/full-track/album-detail.do";

	public String getDetailURL() {
		return detailURL;
	}


	public String getShortAuthor() {
		return shortAuthor;
	}

	public long getGenreId() {
		return genreId;
	}

	public void setGenreId(long genreId) {
		this.genreId = genreId;
	}

	public String getGenreName() {
		return genreName;
	}

	public void setGenreName(String genreName) {
		this.genreName = genreName;
	}

	public String getUpc() {
		return upc;
	}

	public void setUpc(String upc) {
		this.upc = upc;
		this.updateDetailURL();
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
		updateTooltips();
		this.shortAuthor = this.createShortString(this.author, MaxAuthorLen);
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
		updateTooltips();
		updateDetailURL();
		this.shortTitle = this.createShortString(this.title, MaxTitleLen);
	}

	public Date getReleaseDate() {
		return releaseDate;
	}

	public void setReleaseDate(Date releaseDate) {
		this.releaseDate = releaseDate;
	}

	public String getCoverImagePath() {
		return coverImagePath;
	}

	public void setCoverImagePath(String coverImagePath) {
		this.coverImagePath = coverImagePath;
	}
	
	protected void updateTooltips() {
		imgageTooltip = this.author + " - " + this.title;
	}
	
	private void updateDetailURL() {
		try {
			detailURL = "/entertainment/full-track/album-detail.do";
			detailURL += "?upc="+this.upc;
			
			if(this.title != null) {
				detailURL += "&title="+ URLEncoder.encode(this.title, Item.encoding);
			}
			
		} catch (UnsupportedEncodingException ue) {
			Logger.LOG_NOHUP.error(ue);
		} catch (Exception ex) {
			Logger.LOG_NOHUP.error(ex);
		}
	}


	@Override
	public void escapeHtml() {
		this.author = StringEscapeUtils.escapeHtml(this.author);
		this.title = StringEscapeUtils.escapeHtml(this.title);
		this.genreName = StringEscapeUtils.escapeHtml(this.genreName);
	}
	
	@Override
	public void unescapeHtml() {
		this.author = StringEscapeUtils.unescapeHtml(this.author);
		this.title = StringEscapeUtils.unescapeHtml(this.title);
		this.genreName = StringEscapeUtils.unescapeHtml(this.genreName);
	}

}
